﻿using System.Runtime.InteropServices;

namespace TroubleshootingofBeanBagAssistant.lCheck
{
	public class ProcessStatusCheck : IDiagnosticCheck
	{
		public string Name => "检查AIMouse进程状态";

		[DllImport("user32.dll")]
		[return: MarshalAs(UnmanagedType.Bool)]
		static extern bool IsHungAppWindow(IntPtr hWnd);

		public CheckResult Run()
		{
			// 查找窗口句柄
			IntPtr hWnd = Win32.FindWindow(null, "AIMouse");
			if (hWnd != IntPtr.Zero)
			{
				bool isHung = IsHungAppWindow(hWnd);
				string status = isHung ? "无响应" : "正常";
				return new CheckResult
				{
					Title = $"发现了在运行的AIMouse（{status}）",
					Detail = isHung ? "建议重启应用" : "已解决"
				};
			}
			else
			{
				return new CheckResult
				{
					Title = "没有异常运行的AIMouse。",
					Detail = "无需处理"
				};
			}
		}
	}


}
